﻿using Ebusiness_ProductService.Models;
using Ebusiness_ProductService.Repositorys;
using Ebusiness_ProductService.Services.Dtos.Product;
using Volo.Abp;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace Ebusiness_ProductService.Services
{
    [RemoteService(IsEnabled = false)]
    [Dependency(ServiceLifetime.Singleton)]
    public class ProductService : CrudAppService<Product, ProductDto, Guid>, IProductService
    {
        public ProductService(IProductRepository repository) : base(repository)
        {

        }

        //应用服务：聚合间、和外部系统的业务逻辑
        public override async Task<ProductDto> CreateAsync(ProductDto input)
        {
            //Console.WriteLine("当前线程 ID2 是: " + Thread.CurrentThread.ManagedThreadId);
            ////Thread.Sleep(6000);
            //await Task.Delay(6000);
            //Console.WriteLine("当前线程 ID3 是: " + Thread.CurrentThread.ManagedThreadId);
            Product product = ObjectMapper.Map<ProductDto, Product>(input);
            product.geoType = GeoType.CNY;
            product.Geo = new Geo(12,12);
            await Repository.InsertAsync(product);
            return input;
        }
    }
}
